import org.example.Triangle;

import java.awt.font.LineMetrics;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class GenerateTestCase {
    public static void main(String[] args) {
//         generateGeneralityBoundCase();
//        generateRobustBoundCase();
//        generateWorstGeneralityBoundCase();
        generateWorstRobustBoundCase();
    }

    public static void generateGeneralityBoundCase(){
        ArrayList<String> cases = new ArrayList<>();
        // 一般边界值测试，单缺陷假设,只有一个值在边界内（合法数据）和在边界上（合法数据）
        ArrayList<int[]> oriData = new ArrayList<>();
        // 一个变量在边界上
        oriData.add(new int[]{1,5,6});
        oriData.add(new int[]{100,99,99});
        oriData.add(new int[]{99,62,62});
        oriData.add(new int[]{2,3,3});
        for (int m = 0; m < oriData.size(); m++){
            for (int i = 0; i < 3; i++){
                int a = oriData.get(m)[i];
                for (int j = i + 1; j < 3; j++){
                    int b = oriData.get(m)[j % 3];
                    for (int k = j + 1; j < 3; j++){
                        int c = oriData.get(m)[k % 3];
                        if (m == 0) cases.add(a + "," + b + "," + c + ",非三角形\n");
                        else cases.add(a + "," + b + "," + c + ",等腰三角形\n");
                    }
                }
            }
        }
        // 最后再插入一个全在中间的数据
        cases.add(3 + "," + 4 + "," + 5 + ",不等边三角形\n");
        // 生成4n+1=13条数据
        insertCasesToCSV(cases);
    }

    public static void generateRobustBoundCase(){
        // 健壮边界值分析，单缺陷假设，只有一个值出现在 边界外（非法数据）|边界上|边界内
        ArrayList<String> cases = new ArrayList<>();
        ArrayList<int[]> oriData = new ArrayList<>();
        oriData.add(new int[]{1,5,6});
        oriData.add(new int[]{100,99,99});
        oriData.add(new int[]{99,62,62});
        oriData.add(new int[]{2,3,3});
        oriData.add(new int[]{101,66,55});
        oriData.add(new int[]{0,1,1});
        for (int m = 0; m < oriData.size(); m++){
            for (int i = 0; i < 3; i++){
                int a = oriData.get(m)[i];
                for (int j = i + 1; j < 3; j++){
                    int b = oriData.get(m)[j % 3];
                    for (int k = j + 1; j < 3; j++){
                        int c = oriData.get(m)[k % 3];
                        if (m == 0) cases.add(a + "," + b + "," + c + ",非三角形\n");
                        else if (m == 5 || m == 4) cases.add(a + "," + b + "," + c + ",输入错误\n");
                        else cases.add(a + "," + b + "," + c + ",等腰三角形\n");
                    }
                }
            }
        }
        // 最后在插入一个全在中间的数据
        cases.add(3 + "," + 4 + "," + 5 + ",不等边三角形\n");
        // 生成6n+1=19条数据
        insertCasesToCSV(cases);
    }

    public static void generateWorstGeneralityBoundCase(){
        // 一般最坏情况边界分析，多缺陷假设（有0个、一个或多个变量出现在边界上）
        ArrayList<String> cases = new ArrayList<>();
        int[] data = new int[]{1,100,2,99,35};
        for (int i = 0; i < data.length; i++){
            for (int j = 0; j < data.length; j++){
                for (int k = 0; k < data.length; k++){
                    Triangle triangle = new Triangle();
                    String classify = triangle.classify(data[i], data[j], data[k]);
                    cases.add(data[i] + "," + data[j] + "," + data[k] + "," + classify + "\n");
                }
            }
        }
        // 生成5^n=125条测试样例
        insertCasesToCSV(cases);
    }

    public static void generateWorstRobustBoundCase(){
        // 最坏情况健壮性边界分析，多缺陷假设（有0个、一个或多个变量出现在边界上或边界外）
        ArrayList<String> cases = new ArrayList<>();
        int[] data = new int[]{0,1,100,101,2,99,35};
        for (int i = 0; i < data.length; i++){
            for (int j = 0; j < data.length; j++){
                for (int k = 0; k < data.length; k++){
                    Triangle triangle = new Triangle();
                    String classify = triangle.classify(data[i], data[j], data[k]);
                    cases.add(data[i] + "," + data[j] + "," + data[k] + "," + classify + "\n");
                }
            }
        }
        // 生成7^n=343条测试样例
        insertCasesToCSV(cases);
    }

    public static void insertCasesToCSV(ArrayList<String> cases){
        BufferedWriter bw = null;
        try {
            bw = new BufferedWriter(new FileWriter("E:\\java_project\\软件测试\\作业2\\code\\testCode2\\src\\test\\resources\\triangle.csv", true));
            for (String minCase : cases){
                bw.write(minCase);
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                bw.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
